﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PhotoList.Dal;

namespace PhotoList.Web
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CheckSession();
        }

        protected bool CheckSession()
        {
            if (base.Session["QT_UID"] == null)
            {
                string myScript = "<script anguage='javascript' type='text/javascript'>window.location.href='Login.aspx';</script>";
                this.Response.Write(myScript);
                this.Response.End();

                return false;
            }

            PhotoList.Dal.User uUser = new PhotoList.Dal.User(base.Session["QT_UID"].ToString());

            if (uUser.Uid == "")
            {
                string myScript = "<script anguage='javascript' type='text/javascript'>window.location.href='Login.aspx';</script>";
                this.Response.Write(myScript);
                this.Response.End();

                return false;
            }

            Page.Session["QT_UID"] = uUser.Uid.Trim();
            Page.Session["QT_PASS"] = uUser.Pass.Trim();

            return true;
        }

        //private void DirectoriesList()
        //{
        //    string path = ConfigurationManager.AppSettings["HomeDirectory"].ToString();
        //    DirectoryInfo[] Directories = PhotoList.Dal.IO.GetDirectories(Server.MapPath(path));

        //    this.Label1.Text = path;

        //    foreach (DirectoryInfo dir in Directories)
        //    {
        //        this.lbox1.Items.Add(dir.ToString());
        //    }
        //}

        //private void FilesList()
        //{
        //    string path = ConfigurationManager.AppSettings["HomeDirectory"].ToString();
        //    FileInfo[] Files = PhotoList.Dal.IO.GetFiles(Server.MapPath(path));

        //    this.Label2.Text = path;

        //    foreach (FileInfo file in Files)
        //    {
        //        this.ListBox2.Items.Add(file.ToString());
        //    }
        //}
    }
}